function fn_wrap(raw, success, fail){
    var resp = eval(raw);
    var state = resp[0];
    var data = resp[1];
    if (state == '200') {
        return success(state, data);
    } else {
        return fail(state, data);
    }
}


function save_block_pos_do(order_ids, fn, fn_fail) {
    $.post('/saveBlockPos.do', 
        {'ordered_ids': order_ids.toString()},
        function (raw) {
            fn_wrap(raw, fn , fn_fail);
        });
}

function save_block_tag_do(block_id, tags) {
    $.get('/saveBlockTag.do', 
        {'block_id': block_id, 'tags': tags.toString() },
        function (raw) {
            save_block_tag_cb(raw);
        });
}

function save_block_content_do(id, content, fn, fn_fail) {
    $.post('/saveBlockContent.do', 
        {'id':id, 'content':content}, 
        function(raw) {
            fn_wrap(raw, fn, fn_fail);
        });
}

function add_note_do(title, fn, fn_fail) {
    $.get('/addNote.do', {'title':title}, function (raw) {
        fn_wrap(raw, fn, fn_fail);
    });
}

function add_block_do(note_id, content, fn, fn_fail) {
    $.get('/addBlock.do', {'note_id':note_id, 'content':content}, 
        function (raw) {
            fn_wrap(raw, fn, fn_fail);
        }
    );
}

function rename_note_do(id, title, fn, fn_fail) {
    $.get('/renameNote.do', { 'id': id, 'title':title }, function(data){
        fn_wrap(data, fn, fn_fail);
    });
}

function remove_note_do(id, fn, fn_fail) {
    $.get('/removeNote.do', { 'id': id }, function(data){
        fn_wrap(data, fn, fn_fail);
    });
}

function remove_block_do(id) {
    $.get('/removeBlock.do', { 'id': id }, function(data){
        remove_block_cb(data)
    });
}

function get_block_list_do(note_id, fn, fn_fail) {
    $.get('/listBlock.do', {'note_id': note_id }, function (raw) {
        fn_wrap(raw, fn, fn_fail);
    });
}

function get_note_list_do(fn, fn_fail) {
    $.get('/listNote.do', function (raw) {
        fn_wrap(raw, fn, fn_fail)
    });
}

function get_tag_list_do(count, fn, fn_fail) {
    $.get('/listTag.do', {'count': count},
        function (raw) {
            fn_wrap(raw, fn, fn_fail); 
        });
}

function update_block_tag_list_do(block_id) {
    $.get('/listBlockTag.do', {'block_id': block_id}, function (data) {
        update_block_tag_list_cb(data); 
    });
}

